﻿using System.Collections.Generic;
using System.Threading.Tasks;

namespace Sidvall.Logging
{
    public class LogCollection : System.Collections.ObjectModel.Collection<ILog>, ILog
    {
        #region Public Members

        #region ShouldLog

        public bool ShouldLog(IEnumerable<string> categories, EventType severity)
        {
            if (this.Count == 0)
                return false;
            foreach (var item in this)
            {
                if (item.ShouldLog(categories, severity))
                    return true;
            }
            return false;
        }

        #endregion
        #region WriteAsync

        public async Task WriteAsync(string title, string message, IEnumerable<string> categories, EventType severity, IDictionary<string, string> properties)
        {
            if (this.Count == 0)
                return;
            var tasks = new List<Task>();
            foreach (var item in this)
                tasks.Add(item.WriteAsync(title, message, categories, severity, properties));
            await Task.WhenAll(tasks).ConfigureAwait(false);
        }

        #endregion
        #region ToString

        public override string ToString()
        {
            return "Log - LogCollection";
        }

        #endregion

        #endregion
        #region Constructors

        public LogCollection()
        {
        }

        #endregion
    }
}
